﻿@model Transport.Areas.Administrator.Models.TrackingModel
@{
    var isImportStatus = Model.Status == (int)Transport.Core.Models.Parcels.TrackingStatus.EnumTrackingStatus.Import;
}
@using (Html.BeginForm("Save", "Tracking", FormMethod.Post))
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Areas/Administrator/Content/images/ico-catalog.png")" alt="" />
            @(Model.TrackingId > 0 ? "Chi tiết định vị bưu phẩm" : "Tạo mới định vị bưu phẩm")
        </div>
        <div class="options">
			@if(!isImportStatus)
			{
            <button type="submit" name="save" value="Save" tabindex="6" class="t-button">Lưu</button>
			}
            <a href="@Url.Action("index")" tabindex="8" class="t-button">Quay về</a>
        </div>
    </div>
    
    @Html.HiddenFor(model => model.TrackingId)
    @Html.HiddenFor(model => model.ParcelId)
    @Html.HiddenFor(model => model.TrackingNumbers)
    <table width="99%">
        <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Mã vận đơn")
            </td>
            <td class="adminData">
                @Html.TextBoxFor(model => model.TrackingNumbers, new { disabled = "disabled", style = "background:#ebebe4" })
                @Html.ValidationMessageFor(model => model.TrackingNumbers)
            </td>
        </tr>
        <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Nơi đi")
            </td>
            <td class="adminData">
                @Html.TextBoxFor(model => model.DeliverFromName, new { disabled = "disabled", style = "background:#ebebe4" })
            </td>
        </tr>
        <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Nơi đến")
            </td>
            <td class="adminData">
                @Html.TextBoxFor(model => model.DeliverToName, new { disabled = "disabled", style = "background:#ebebe4" })
            </td>
        </tr>
        <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Khách gửi")
            </td>
            <td class="adminData">
                @Html.TextBoxFor(model => model.CustomerName, new { disabled = "disabled", style = "background:#ebebe4" })
            </td>
        </tr>
        @if (isImportStatus)
        {
        <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Ngày gửi")
                <span class="field_required">*</span>
            </td>
            <td style="padding-bottom:5px">
                @Html.Telerik().DateTimePickerFor(model => model.DateOfSending).Enable(false)
                @Html.ValidationMessageFor(model => model.DateOfSending)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.Label("Tỉnh thành")
                <span class="field_required">*</span>
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.StateProvinceId, new SelectList(Model.StateProvinces, "StateProvinceId", "StateProvinceName"), "-Chọn-", new { disabled = "disabled", style = "background:#ebebe4" })
                @Html.ValidationMessageFor(model => model.StateProvinceId, "Tỉnh thành là bắt buộc chọn.")
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.Label("Bưu cục")
                <span class="field_required">*</span>
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.PostOfficeId, new SelectList(Model.PostOffices, "PostOfficeId", "PostOfficeName"), "-Chọn-", new { disabled = "disabled", style = "background:#ebebe4" })
                @Html.ValidationMessageFor(model => model.PostOfficeId, "Bưu cục là bắt buộc chọn.")
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.Label("Trạng thái")
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.Status, new SelectList(Transport.Core.Models.Parcels.TrackingStatus.GetTrackingStatusHaveImport(), "Value", "Text"), new { disabled = "disabled", style = "background:#ebebe4" })
            </td>
        </tr>
        }
        else
        {
            <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Ngày")
                <span class="field_required">*</span>
            </td>
            <td style="padding-bottom:5px">
                @Html.Telerik().DateTimePickerFor(model => model.DateOfSending)
                @Html.ValidationMessageFor(model => model.DateOfSending)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.Label("Tỉnh thành")
                <span class="field_required">*</span>
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.StateProvinceId, new SelectList(Model.StateProvinces, "StateProvinceId", "StateProvinceName"), "-Chọn-")
                @Html.ValidationMessageFor(model => model.StateProvinceId, "Tỉnh thành là bắt buộc chọn.")
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.Label("Trạng thái")
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.Status, new SelectList(Transport.Core.Models.Parcels.TrackingStatus.GetTrackingStatus(), "Value", "Text"))
            </td>
        </tr>
        }
        <tr id="trReceivedDate" @(Model.Status != (int)Transport.Core.Models.Parcels.TrackingStatus.EnumTrackingStatus.Success ? "style=display:none" : "")>
            <td width="100" class="adminTitle">
                @Html.Label("Ngày nhận")
                <span class="field_required">*</span>
            </td>
            <td style="padding-bottom:5px">
                @Html.Telerik().DateTimePickerFor(model => model.ReceivedDate)
                @Html.ValidationMessageFor(model => model.ReceivedDate)
            </td>
        </tr>
        <tr id="trReceiver" @(Model.Status != (int)Transport.Core.Models.Parcels.TrackingStatus.EnumTrackingStatus.Success ? "style=display:none" : "")>
            <td width="100" class="adminTitle">
                @Html.Label("Người nhận")
                <span class="field_required">*</span>
            </td>
            <td class="adminData">
                @Html.TextBoxFor(model => model.Receiver)
                @Html.ValidationMessageFor(model => model.Receiver)
            </td>
        </tr>
    </table>
}
@Html.Osd().HiddenPopupWindow("Cảnh Báo", Helpers.DeleteConfirmMessageBox("Bạn có thực sự muốn xóa không", @Url.Action("delete", "Tracking", new { area = "administrator" })).ToHtmlString())
<div class="section-header">
    <div class="title">
        <img alt="" src="@Url.Content("~/Areas/Administrator/Content/images/ico-catalog.png")">
        Danh sách các định vị:
    </div>
    @if (Model.TrackingId > 0)
    {
        <div class="options">
            <a href="@Url.Action("Create", "Tracking", new { parcelId = Model.ParcelId })" tabindex="8" class="t-button">Tạo mới định vị cho bưu phẩm này</a>
        </div>
    }
</div>
@(Html.Telerik().Grid<Transport.Areas.Administrator.Models.TrackingModel>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(x => x.TrackingId).Title("MS").ClientTemplate("<a href=\"" + Url.Action("Edit", "Tracking", new { area = "Administrator", id = "" }) + "/<#= TrackingId #>\"><#= 10000 + TrackingId #></a>")
                        .Width(100)
                        .Filterable(false);
        columns.Bound(x => x.TrackingNumbers).Title("Số Vận Đơn")
            .Width(150)
            .Filterable(false);
        columns.Bound(x => x.DeliverToName).Title("Hành Trình")
            .Width(250)
            .Filterable(false);
        columns.Bound(x => x.DateOfSending).Title("Ngày Gửi").Format("{0:H:mm - dd/MM/yyyy}")
            .Width(150)
            .Filterable(false);
        columns.Bound(x => x.UserFullName).Title("Nhân Viên")
            .Filterable(false);
        columns.Bound(x => x.StatusName).Title("Trạng Thái")
            .Width(200)
            .Filterable(false);
        columns.Bound(p => p.TrackingId)
            .ClientTemplate("<a onclick='onMessageBoxActionDelete(<#= TrackingId #>)'><img src=\"" + Url.Content("~/Content/Images/delete_16_16.png") + "\" /></a>")
            .HtmlAttributes(new { style = "text-align:center" })
            .Title(string.Empty)
            .Width(100).Sortable(false)
            .Filterable(false);
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("GetTrackings", "Tracking", new { parcelId = Model.ParcelId }))
    .Pageable()
    .Sortable()
    .Scrollable()
        .Groupable(grouping => grouping.Enabled(false))
    .Filterable()
) 
<script type="text/javascript">
    $(document).ready(function () {
        jQuery.validator.methods["date"] = function (value, element) { return true; };
        $('#Status').change(function () {
            var status = $(this).val();
            if (status == "@((int)Transport.Core.Models.Parcels.TrackingStatus.EnumTrackingStatus.Success)") {
                $('#trReceivedDate').show();
                $('#trReceiver').show();
            }
            else {
                $('#trReceivedDate').hide();
                $('#trReceiver').hide();
            }
        });
    });
</script>